package com.example.myapplication.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.myapplication.Helper.TodayHelper;
import com.example.myapplication.R;
import com.example.myapplication.bean.ImportBean;
import com.example.myapplication.bean.TodayBean;

import java.util.ArrayList;

public class TodayAdapter extends ArrayAdapter<TodayBean> {
    private int resourceId;
    private Context context;
    private ArrayList<TodayBean> dataSet;

    public TodayAdapter(@NonNull Context context, int resource, @NonNull ArrayList<TodayBean> objects) {
        super(context, resource,objects);
        this.context = context;
        this.resourceId = resource;
        this.dataSet = objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Todayholder todayholder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(resourceId, null);
            todayholder = new Todayholder();
            todayholder.title = convertView.findViewById(R.id.til_txt);
            todayholder.date = convertView.findViewById(R.id.date_txt);
            todayholder.time = convertView.findViewById(R.id.time_txt);
            todayholder.book = convertView.findViewById(R.id._book);
            convertView.setTag(todayholder);
        } else {
            todayholder = (Todayholder) convertView.getTag();
        }
        final TodayBean todayBean = dataSet.get(position);
        Log.v("t", todayBean.getTitle_txt());
        Log.v("t",todayBean.getYear()+"年"+todayBean.getMonth()+"月"+todayBean.getDay()+"日");
        Log.v("t", todayBean.getHour()+"时"+todayBean.getMin()+"分");
        todayholder.title.setText(todayBean.getTitle_txt());
        todayholder.date.setText(todayBean.getYear()+"年"+todayBean.getMonth()+"月"+todayBean.getDay()+"日");
        todayholder.time.setText(todayBean.getHour()+"时"+todayBean.getMin()+"分");
        todayholder.book.setText(todayBean.getBook());

        return convertView;
    }

    public class Todayholder {
        TextView title;
        TextView date;
        TextView time;
        TextView book;
    }
}
